package kr.hkit.powerjava.chapter22.work2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;

import kr.hkit.powerjava.chapter22.work2.dao.StudentManagerImpl;
import kr.hkit.powerjava.chapter22.work2.vo.Student;

public class TestMain {
	public static void main(String[] args) {
		
		ArrayList<Student> stdList = new ArrayList<>();
		StudentManagerImpl sm = new StudentManagerImpl(stdList);
		
		//추가
		Student std1 = new Student(1, "김태희",90,90,90);
		sm.addItem(std1);
		Student std2 = new Student(2, "제시카", 89, 79, 66);
		sm.addItem(std2);
		sm.addItem(new Student(3, "이연희", 80, 80, 80));
		sm.addItem(new Student(4, "임수정", 90, 80, 90));
		//삭제
/*		sm.delItem(std1);
		sm.delItem(std2);*/
		//검색
		Student searchItem = new Student(1,"김태희");
		String result = sm.searchItem(searchItem)?"존재":"음슴";
		System.out.println(searchItem.getStdNum() + ":" + searchItem.getStdNname() + " = " + result);
//		boolean isSearch = sm.searchItem(new Student(1,"김태희"));
		/*System.out.println(isSearch);*/
/*		temp = sm.searchItem(new Student(2,"제시카"));
		System.out.println(temp);*/
		//수정
		Student updateItem = new Student(1, "김태희",92,92,90);
		sm.updateItem(updateItem);
		
		//출력
		
		System.out.println("총점 순 정렬(내림차순)");
		Comparator<Student> totalCom = new Comparator<Student>() {
			
			@Override
			public int compare(Student o1, Student o2) {
				return (int) (o2.getTotal() - o1.getTotal());
			}
		};
		sm.pinItems(totalCom);
		System.out.println("이름순 정렬(오름차순)");
		Comparator<Student> com = new Comparator<Student>() {
			
			@Override
			public int compare(Student o1, Student o2) {
				return o1.getStdNname().hashCode()-o2.getStdNname().hashCode();
			}
		};
		sm.pinItems(com);
		System.out.println("국어순 정렬");
		sm.pinItems(/*Comparator<Student> korCom = */new Comparator<Student>() {
			
			@Override
			public int compare(Student o1, Student o2) {
				return o2.getKor() - o1.getKor();
			}
		});
//		sm.pinItems(korCom);		
		for (Student std : stdList) {
			System.out.println(std);
			
		}
		
		Collections.shuffle(stdList);
		
		System.out.println("반복자=========");
		Student std = null;
		Iterator<Student> iterator = stdList.iterator();
		while(iterator.hasNext()){
			std = iterator.next();
			System.out.println(std);
		}
		
		

	}
	
	
}
